<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>FabGL: VGA/InputBox/InputBox.ino</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">FabGL
   </div>
   <div id="projectbrief">ESP32 Display Controller and Graphics Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('_v_g_a_2_input_box_2_input_box_8ino-example.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">VGA/InputBox/InputBox.ino</div>  </div>
</div><!--header-->
<div class="contents">
<p>InputBox UI wizard</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment">  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - &lt;http://www.fabgl.com&gt;</span></div><div class="line"><span class="comment">  Copyright (c) 2019-2021 Fabrizio Di Vittorio.</span></div><div class="line"><span class="comment">  All rights reserved.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">* Please contact fdivitto2013@gmail.com if you need a commercial license.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">* This library and related software is available under GPL v3.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is free software: you can redistribute it and/or modify</span></div><div class="line"><span class="comment">  it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment">  the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><span class="comment">  (at your option) any later version.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment">  but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment">  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div><div class="line"><span class="comment">  GNU General Public License for more details.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment">  along with FabGL.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;WiFi.h&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="fabgl_8h.html">fabgl.h</a>&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="inputbox_8h.html">inputbox.h</a>&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> setup()</div><div class="line">{</div><div class="line">  <span class="comment">//Serial.begin(115200); delay(500); Serial.write(&quot;\n\n\n&quot;); // DEBUG ONLY</span></div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> loop()</div><div class="line">{</div><div class="line">  <span class="comment">// initializes input box</span></div><div class="line">  InputBox ib;</div><div class="line">  ib.begin();</div><div class="line"></div><div class="line">  ib.message(<span class="stringliteral">&quot;Welcome!&quot;</span>, <span class="stringliteral">&quot;Welcome to FabGL InputBox demo!&quot;</span>);</div><div class="line"></div><div class="line"></div><div class="line">  <span class="comment">// Example of progress bar</span></div><div class="line">  <a name="a0"></a><a class="code" href="group___enumerations_ga25f6dff2b7711962b46d7c9313d28aa2.html#ga25f6dff2b7711962b46d7c9313d28aa2">InputResult</a> r = ib.progressBox(<span class="stringliteral">&quot;Example of Progress Bar&quot;</span>, <span class="stringliteral">&quot;Abort&quot;</span>, <span class="keyword">true</span>, 200, [&amp;](fabgl::ProgressApp * app) {</div><div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt;= 100; ++i) {</div><div class="line">      <span class="keywordflow">if</span> (!app-&gt;update(i, <span class="stringliteral">&quot;Index is %d/100&quot;</span>, i))</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      delay(40);</div><div class="line">    }</div><div class="line">    delay(800);</div><div class="line">  });</div><div class="line">  <span class="keywordflow">if</span> (r == InputResult::Cancel)</div><div class="line">    ib.message(<span class="stringliteral">&quot;&quot;</span>, <span class="stringliteral">&quot;Operation Aborted&quot;</span>);</div><div class="line"></div><div class="line"></div><div class="line">  <span class="comment">// Example of simple menu (items from separated strings)</span></div><div class="line">  <span class="keywordtype">int</span> s = ib.menu(<span class="stringliteral">&quot;Example of simple Menu&quot;</span>, <span class="stringliteral">&quot;Click on one item&quot;</span>, <span class="stringliteral">&quot;Item number zero;Item number one;Item number two;Item number three&quot;</span>);</div><div class="line">  ib.messageFmt(<span class="stringliteral">&quot;&quot;</span>, <span class="keyword">nullptr</span>, <span class="stringliteral">&quot;OK&quot;</span>, <span class="stringliteral">&quot;You have selected item %d&quot;</span>, s);</div><div class="line"></div><div class="line"></div><div class="line">  <span class="comment">// Example of simple menu (items from StringList)</span></div><div class="line">  fabgl::StringList list;</div><div class="line">  list.append(<span class="stringliteral">&quot;Option Zero&quot;</span>);</div><div class="line">  list.append(<span class="stringliteral">&quot;Option One&quot;</span>);</div><div class="line">  list.append(<span class="stringliteral">&quot;Option Two&quot;</span>);</div><div class="line">  list.append(<span class="stringliteral">&quot;Option Three&quot;</span>);</div><div class="line">  list.select(1, <span class="keyword">true</span>);</div><div class="line">  s = ib.menu(<span class="stringliteral">&quot;Menu&quot;</span>, <span class="stringliteral">&quot;Click on an item&quot;</span>, &amp;list);</div><div class="line">  ib.messageFmt(<span class="stringliteral">&quot;&quot;</span>, <span class="keyword">nullptr</span>, <span class="stringliteral">&quot;OK&quot;</span>, <span class="stringliteral">&quot;You have selected item %d&quot;</span>, s);</div><div class="line"></div><div class="line"></div><div class="line">  <span class="comment">// Example of options selection box with OK button (items from separated strings) and autoOK of 5 seconds</span></div><div class="line">  s = ib.select(<span class="stringliteral">&quot;Download Boot Disk&quot;</span>, <span class="stringliteral">&quot;Select boot disk to download&quot;</span>, <span class="stringliteral">&quot;FreeDOS;Minix 2.0;MS-DOS 5&quot;</span>, <span class="charliteral">&#39;;&#39;</span>, <span class="stringliteral">&quot;Cancel&quot;</span>, <span class="stringliteral">&quot;OK&quot;</span>, 5);</div><div class="line">  ib.messageFmt(<span class="stringliteral">&quot;&quot;</span>, <span class="keyword">nullptr</span>, <span class="stringliteral">&quot;OK&quot;</span>, <span class="stringliteral">&quot;You have selected item %d&quot;</span>, s);</div><div class="line"></div><div class="line"></div><div class="line">  <span class="comment">// Example of options selection box with OK button (items from StringList)</span></div><div class="line">  fabgl::StringList quiz;</div><div class="line">  quiz.append(<span class="stringliteral">&quot;A) Connecting to the network&quot;</span>);</div><div class="line">  quiz.append(<span class="stringliteral">&quot;B) Creating new user accounts&quot;</span>);</div><div class="line">  quiz.append(<span class="stringliteral">&quot;C) Providing power to the computer&quot;</span>);</div><div class="line">  quiz.append(<span class="stringliteral">&quot;D) Connecting smartphones and other peripherals&quot;</span>);</div><div class="line">  <span class="keywordflow">if</span> (ib.select(<span class="stringliteral">&quot;QUIZ&quot;</span>, <span class="stringliteral">&quot;What is an Ethernet port used for?&quot;</span>, &amp;quiz, <span class="keyword">nullptr</span>, <span class="stringliteral">&quot;Submit&quot;</span>) == InputResult::Enter) {</div><div class="line">    ib.message(<span class="stringliteral">&quot;Result&quot;</span>, quiz.selected(0) ? <span class="stringliteral">&quot;That&#39;s right, great job!&quot;</span> : <span class="stringliteral">&quot;Sorry, that&#39;s not correct&quot;</span>);</div><div class="line">  }</div><div class="line"></div><div class="line"></div><div class="line">  <span class="comment">// Example of text input box</span></div><div class="line">  <span class="keywordtype">char</span> name[32] = <span class="stringliteral">&quot;&quot;</span>;</div><div class="line">  <span class="keywordflow">if</span> (ib.textInput(<span class="stringliteral">&quot;Asking name&quot;</span>, <span class="stringliteral">&quot;What&#39;s your name?&quot;</span>, name, 31) == InputResult::Enter)</div><div class="line">    ib.messageFmt(<span class="stringliteral">&quot;&quot;</span>, <span class="keyword">nullptr</span>, <span class="stringliteral">&quot;OK&quot;</span>, <span class="stringliteral">&quot;Nice to meet you %s!&quot;</span>, name);</div><div class="line"></div><div class="line"></div><div class="line">  <span class="comment">// Example WiFi connection wizard</span></div><div class="line">  <span class="keywordflow">if</span> (ib.message(<span class="stringliteral">&quot;WiFi Configuration&quot;</span>, <span class="stringliteral">&quot;Configure WiFi?&quot;</span>, <span class="stringliteral">&quot;No&quot;</span>, <span class="stringliteral">&quot;Yes&quot;</span>) == InputResult::Enter) {</div><div class="line"></div><div class="line">    <span class="comment">// yes, scan for networks showing a progress dialog box</span></div><div class="line">    <span class="keywordtype">int</span> networksCount = 0;</div><div class="line">    ib.progressBox(<span class="stringliteral">&quot;&quot;</span>, <span class="keyword">nullptr</span>, <span class="keyword">false</span>, 200, [&amp;](fabgl::ProgressApp * app) {</div><div class="line">      app-&gt;update(0, <span class="stringliteral">&quot;Scanning WiFi networks...&quot;</span>);</div><div class="line">      networksCount = WiFi.scanNetworks();</div><div class="line">    });</div><div class="line"></div><div class="line">    <span class="comment">// are there available WiFi?</span></div><div class="line">    <span class="keywordflow">if</span> (networksCount &gt; 0) {</div><div class="line"></div><div class="line">      <span class="comment">// yes, show a selectable list</span></div><div class="line">      fabgl::StringList list;</div><div class="line">      <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; networksCount; ++i)</div><div class="line">        list.appendFmt(<span class="stringliteral">&quot;%s (%d dBm)&quot;</span>, WiFi.SSID(i).c_str(), WiFi.RSSI(i));</div><div class="line">      <span class="keywordtype">int</span> s = ib.menu(<span class="stringliteral">&quot;WiFi Configuration&quot;</span>, <span class="stringliteral">&quot;Please select a WiFi network&quot;</span>, &amp;list);</div><div class="line"></div><div class="line">      <span class="comment">// user selected something?</span></div><div class="line">      <span class="keywordflow">if</span> (s &gt; -1) {</div><div class="line"></div><div class="line">        <span class="comment">// yes, ask for WiFi password</span></div><div class="line">        <span class="keywordtype">char</span> psw[32] = <span class="stringliteral">&quot;&quot;</span>;</div><div class="line">        <span class="keywordflow">if</span> (ib.textInput(<span class="stringliteral">&quot;WiFi Configuration&quot;</span>, <span class="stringliteral">&quot;Insert WiFi password&quot;</span>, psw, 31, <span class="stringliteral">&quot;Cancel&quot;</span>, <span class="stringliteral">&quot;OK&quot;</span>, <span class="keyword">true</span>) == InputResult::Enter) {</div><div class="line"></div><div class="line">          <span class="comment">// user pressed OK, connect to WiFi...</span></div><div class="line">          <span class="keywordtype">char</span> SSID[50];</div><div class="line">          strcpy(SSID, WiFi.SSID(s).c_str());</div><div class="line">          <span class="keywordtype">bool</span> connected = <span class="keyword">false</span>;</div><div class="line">          ib.progressBox(<span class="stringliteral">&quot;&quot;</span>, <span class="keyword">nullptr</span>, <span class="keyword">true</span>, 200, [&amp;](fabgl::ProgressApp * app) {</div><div class="line">            WiFi.begin(SSID, psw);</div><div class="line">            <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 32 &amp;&amp; WiFi.status() != WL_CONNECTED; ++i) {</div><div class="line">              <span class="keywordflow">if</span> (!app-&gt;update(i * 100 / 32, <span class="stringliteral">&quot;Connecting to %s...&quot;</span>, SSID))</div><div class="line">                <span class="keywordflow">break</span>;</div><div class="line">              delay(500);</div><div class="line">              <span class="keywordflow">if</span> (i == 16)</div><div class="line">                WiFi.reconnect();</div><div class="line">            }</div><div class="line">            connected = (WiFi.status() == WL_CONNECTED);</div><div class="line">          });</div><div class="line"></div><div class="line">          <span class="comment">// show to user the connection state</span></div><div class="line">          ib.message(<span class="stringliteral">&quot;&quot;</span>, connected ? <span class="stringliteral">&quot;Connection succeeded&quot;</span> : <span class="stringliteral">&quot;Connection failed&quot;</span>);</div><div class="line"></div><div class="line">        }</div><div class="line">      }</div><div class="line">    } <span class="keywordflow">else</span> {</div><div class="line">      <span class="comment">// there is no WiFi</span></div><div class="line">      ib.message(<span class="stringliteral">&quot;&quot;</span>, <span class="stringliteral">&quot;No WiFi network found!&quot;</span>);</div><div class="line">    }</div><div class="line">    WiFi.scanDelete();</div><div class="line">  }</div><div class="line"></div><div class="line"></div><div class="line">  <span class="comment">// finalizes input box</span></div><div class="line">  ib.end();</div><div class="line"></div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Mon Aug 2 2021 07:08:02 for FabGL by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>
  </ul>
</div>
</body>
</html>
